{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "source": [
    "import sympy as sym\n",
    "import numpy as np\n",
    "import scipy as sp\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from pathlib import Path \n",
    "\n",
    "import os\n",
    "import multiprocessing\n",
    "from joblib import Parallel, delayed\n",
    "num_cores = multiprocessing.cpu_count()\n",
    "print(num_cores)\n",
    "\n",
    "#Define parameter\n",
    "m_total = 9\n",
    "res = 201\n",
    "\n",
    "position = np.linspace(0,6,res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = sym.Symbol('x')\n",
    "y = sym.Symbol('y')\n",
    "\n",
    "z = 1/(2)*(x+sym.I*y)\n",
    "z_conj = 1/(2)*(x-sym.I*y)\n",
    "\n",
    "diffz = lambda w : (sym.diff(w,x) - sym.I*sym.diff(w,y))\n",
    "diffz_conj = lambda w : (sym.diff(w,x) + sym.I*sym.diff(w,y))\n",
    "\n",
    "ad = lambda w : sym.I/(2)**0.5 * ( z_conj * w - diffz(w) )\n",
    "bd = lambda w : 1/(2)**0.5 * ( z * w - diffz_conj(w) )\n",
    "b = lambda w : 1/(2)**0.5 * ( z_conj * w + diffz(w) )\n",
    "\n",
    "phi00 = ( 1/(2*np.pi) )**0.5 * sym.exp( -1*(x**2+y**2)/(4) )\n",
    "\n",
    "phi0 = [ phi00 ]\n",
    "phi1 = [ ad(phi00) ]\n",
    "\n",
    "for i in range(1,m_total):\n",
    "    phi0.append( (1/(i))**0.5 * bd(phi0[i-1]) )\n",
    "    phi1.append( (1/(i))**0.5 * bd(phi1[i-1]) )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### calculate the wavefunction and probability in real space"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "wave0=[]\n",
    "prob0=[]\n",
    "wave1=[]\n",
    "prob1=[]\n",
    "\n",
    "df_0 = pd.DataFrame( )\n",
    "df_1 = pd.DataFrame( )\n",
    "filepath_0 = r'landau_orbit2_0.csv'\n",
    "filepath_1 = r'landau_orbit2_1.csv' \n",
    "\n",
    "df_0['r_(lB)'] = position\n",
    "df_1['r_(lB)'] = position\n",
    "\n",
    "for i in range(m_total):\n",
    "    wave0.append([])\n",
    "    wave1.append([])\n",
    "\n",
    "    tmp_0 = sym.lambdify([x,y],phi0[i])\n",
    "    tmp_1 = sym.lambdify([x,y],phi1[i])\n",
    "\n",
    "    for j in range(len(position)):\n",
    "        wave0[i].append( tmp_0(position[j],0) )\n",
    "        wave1[i].append( tmp_1(position[j],0) )\n",
    "        \n",
    "    prob0.append( abs(np.square(wave0[i])) )\n",
    "    prob1.append( 0.5*(abs(np.square(wave1[i])) + abs(np.square(wave0[i]))) )\n",
    "\n",
    "    #save file\n",
    "    df_0[i] = prob0[i]\n",
    "    df_1[i] = prob1[i]\n",
    "    df_0.to_csv(filepath_0) \n",
    "    df_1.to_csv(filepath_1) \n",
    "    print(i,'is done!')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Princeton",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
